<?php
$dataHelper = $this->helper('\Magezon\LazyLoad\Helper\Data');
$threshold  = (int) $dataHelper->getConfig('general/threshold');
$delay      = (int) $dataHelper->getConfig('general/delay');
$effect     = $dataHelper->getConfig('general/effect');
$effectTime = (int) $dataHelper->getConfig('general/effect_time');
?>
<?php if ($dataHelper->isEnable()) { ?>
<script>
	require(['jquery', 'lazyLoad', 'lazyLoadPlugins'], function($) {
		window.mgzLazyload = function() {
			$('.lazy').lazy({
				bind: "event",
				delay: <?= $delay ? $delay : '-1' ?>,
				threshold: <?= $threshold ?>,
				effect: "<?= $effect ?>",
				effectTime: <?= $effectTime ?>,
				afterLoad: function(element) {
					$(element).removeClass('lazy-loading').addClass('lazy-loaded');
				}
			});
		}
		$(window.mgzLazyload);
		$(document).on('ajaxComplete', function (event, xhr, settings) {
			$(window.mgzLazyload);
		});
		$(document).ready(function($) {
			$('.owl-carousel').on('changed.owl.carousel', function(event) {
		    	$(window.mgzLazyload);
			});
		});
		$('.swiper-container').find('img.lazy-loading').each(function(index, el) {
			var lazySrc = $(this).data('src');
			$(this).removeClass('lazy-loading');
			$(this).addClass('lazy-loaded');
			$(this).attr('src', lazySrc);
		});
		$( document ).ajaxComplete(function() {
			$( ".log" ).text( "Triggered ajaxComplete handler." );
		});
	});
</script>
<?php } ?>